package com.lanou.horo.zhuizhui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.zhuizhui.entity.MustBeChasedItem;
import com.lanou.horo.zhuizhui.utility.imageLoader.AsyncImageLoader;
import com.lanou.horo.zhuizhui.R;
import com.lanou.horo.zhuizhui.utility.imageLoader.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/27.
 */
public class MustBeChasedAdapter extends
        RecyclerView.Adapter<MustBeChasedAdapter.MustBeChasedViewHolder> {
    private List<MustBeChasedItem.ComicsEntity> comicsEntities;
    private ImageLoader imageLoader;
    private Context context;

    public MustBeChasedAdapter(Context context) {
        this.context = context;
        imageLoader = VolleySingleton.getInstance().getImageLoader();
    }
    public void addComList(List<MustBeChasedItem.ComicsEntity> datas){
        comicsEntities = datas;
       notifyDataSetChanged();

    }

    @Override
    public MustBeChasedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.activity_chased_be_must_item,null);
        return new MustBeChasedViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MustBeChasedViewHolder holder, int position) {
        if (comicsEntities != null && comicsEntities.size() > 0){
            MustBeChasedItem.ComicsEntity comicsEntity = comicsEntities.get(position);
            holder.nameTv.setText(comicsEntity.getName());
            holder.lastVolumeTv.setText(comicsEntity.getLast_volume());
            String url = comicsEntity.getCover_img();
            holder.coverImg.setImageUrl(url, imageLoader);
        }

    }

    @Override
    public int getItemCount() {

        return comicsEntities != null && comicsEntities.size() > 0 ? comicsEntities.size() : 0;
    }


    public class MustBeChasedViewHolder extends RecyclerView.ViewHolder{
        private TextView nameTv,lastVolumeTv;
        private NetworkImageView coverImg;

        public MustBeChasedViewHolder(View itemView) {
            super(itemView);
            nameTv = (TextView) itemView.findViewById(R.id.nameTextView);
            lastVolumeTv = (TextView) itemView.findViewById(R.id.lastVolumeTextView);
            coverImg = (NetworkImageView) itemView.findViewById(R.id.coverImageView);
        }
    }

}
